/*
 * PowerWindow.cpp
 *
 *  Created on: 14/11/2012
 *      Author: san
 */

#include "PowerWindow.h"
#include "RedBird.h"
#include "GameSettings.h"
#include "BirdShootingLine.h"
#include "WhiteEgg.h"
#include <iostream>
PowerWindow::PowerWindow() {
	this->add(this->lv);
	this->lv.setBackground("background.jpg");
	this->lv.signal_button_press_event().connect(sigc::mem_fun(*this, &PowerWindow::onClick));
	this->refreshViewDispatcher.connect(sigc::mem_fun(*this, &PowerWindow::refreshScreen));
	this->logicThread = Glib::Thread::create(sigc::mem_fun(*this, &PowerWindow::logicMain), true);
}

PowerWindow::~PowerWindow() {
	// TODO Auto-generated destructor stub
}

void PowerWindow::refreshScreen() {
	match = game->getMatch();
	lv.show(match->getVisibleElements());
}

void PowerWindow::logicMain() {
	level = new Level();
	Pig* pig = new Pig(400, 550);
	BirdShootingLine* bsl = new BirdShootingLine(800, 50, 400, Left);
	level->addPig(pig);
	level->addBirdShootingLine(bsl);
	level->setBackground("background.jpg");
	level->setNumberOfPlayers(1);
	level->setLevelTime(90);
	level->setWidth(900);
	level->setHeight(600);
	player = new Player();
	game = new Game(level, player);
	game->iniciar();
	while (true) {
		this->refreshViewDispatcher();
		usleep(1000000.0 / 24.0);
	}
}

bool PowerWindow::onClick(GdkEventButton *button) {

//	RedBird *rb;
//	// Bird Building Facility
//	Vector2D rbSpeed(-50.0, -50.0);
//	rb = new RedBird(450,300, rbSpeed);
//	// Adding pig for display
//	this->allElements.push_back(rb);
//	// Adding pig to physics
//	this->physicsEngine.add(*rb);
//
//	WhiteEgg *we;
//	Vector2D weSpeed(50.0, 50.0);
//	we = new WhiteEgg(400, 350, weSpeed);
//	this->allElements.push_back(we);
//	this->physicsEngine.add(*we);
	player->shoot(button->x, button->y);


	return true;
}
